package com.zhz.crm.mapper;

import com.zhz.crm.model.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface UserMapper{
    @Insert("INSERT INTO sys_user(user_name,user_password,user_role_id,user_flag)"
            +"values (#{userName},#{userPassword},#{userRoleId},#{userFlag})")
    public void insert(User user);

    @Delete("DELETE FROM sys_user WHERE user_id=#{id}")
    public void delete(Long id);

    @Update("<script>"+"UPDATE sys_user"+
            "<set>"+
            "<if test=\"userName != null\">user_name = #{userName},</if>"+
            "<if test=\"userPassword != null\">user_password = #{userPassword},</if>"+
            "<if test=\"userRoleId != null\">user_role_id = #{userRoleId},</if>"+
            "<if test=\"userFlag != null\">user_flag = #{userFlag},</if>"+
            "</set>"+
            "WHERE user_id = #{userId})"+"</script>")
    public void update(User user);

    @Select("SELECT user_id,user_name,user_password,user_role_id,user_flag"
            +"from sys_user where user_id = #{id}")
    @Results({
            @Result(column = "user_id",property = "userId"),
            @Result(column = "user_name",property = "userName"),
            @Result(column = "user_password",property = "userPassword"),
            @Result(column = "user_role_id",property = "userRoleId"),
            @Result(column = "user_flag",property = "userFlag")
    })
    public User get(Long id );

    @Select("SELECT user_id,user_name,user_password,user_role_id,user_flag from sys_user")
    @Results({
            @Result(column = "user_id",property = "userId"),
            @Result(column = "user_name",property = "userName"),
            @Result(column = "user_password",property = "userPassword"),
            @Result(column = "user_role_id",property = "userRoleId"),
            @Result(column = "user_flag",property = "userFlag")
    })
    public List<User> getAll();
}
